module.exports = function(grunt) {

	// Project configuration.
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),

		banner: '/*! <%= pkg.name %>-<%= pkg.version %>  Generate by <%= grunt.template.today("yyyy-mm-dd")  %>*/\n',

		// 清理文件
		clean: {
			task: {
				src: 'dist'
			}
		},
		// HTML压缩
		htmlmin: {
			task: {
				options: {
					removeComments: true,
					collapseWhitespace: true
				},
				expand: true,
				src: '*.html',
				dest: 'dist'
			}
		},
		// 编译Less文件
		less: {
			task: {
				options: {
					banner: '<%= banner %>'
				},
				src: 'less/core.less',
				dest: 'dist/css/core.css',
			}
		},
		// 自动加前缀
		autoprefixer: {
			task: {
				options: {
					browsers: [
						'Android 2.3',
						'Android >= 4',
						'Chrome >= 20',
						'Firefox >= 24',
						'Explorer >= 8',
						'iOS >= 6',
						'Opera >= 12',
						'Safari >= 6'
					]
				},
				src: 'dist/core.css'
			}
		},
		// CSS语法错误检查
		csslint: {
			task: {
				options: {
					"adjoining-classes": false,
					"box-sizing": false,
					"box-model": false,
					"compatible-vendor-prefixes": false,
					"floats": false,
					"font-sizes": false,
					"gradients": false,
					"important": false,
					"known-properties": false,
					"outline-none": false,
					"qualified-headings": false,
					"regex-selectors": false,
					"shorthand": false,
					"text-indent": false,
					"unique-headings": false,
					"universal-selector": false,
					"unqualified-attributes": false
				},
				src: 'dist/core.css'
			}
		},
		// CSS压缩
		cssmin: {
			task: {
				options: {
					banner: '<%= banner %>'
				},
				src: 'dist/core.css',
				dest: 'dist/css/core.min.css',
			}
		},
		// 合并所有的js
		concat: {
			task: {
				options: {
					banner: '<%= banner %>'
				},
				src: 'js/*.js',
				dest: 'dist/js/core.js'
			}
		},
		// JS语法错误检查
		jshint: {
			task: {
				options: {
					globals: {
						jQuery: true
					},
					// JSHint的更多配置请参考：http://www.jianshu.com/p/4cb23f9e19d3
					"boss": false,
					"curly": true,
					"eqeqeq": true,
					"expr": true,
					"immed": true,
					"newcap": true,
					"noempty": true,
					"noarg": true,
					"undef": true,
					"regexp": true,
					"browser": true,
					"devel": true,
					"node": true
				},
				src: 'dist/core.js'
			}
		},
		// uglify:混淆压缩JS代码
		uglify: {
			task: {
				options: {
					mangle: true
				},
				src: 'dist/js/core.js',
				dest: 'dist/js/core.min.js'
			}
		},
		// 将HTML和Vendor文件备份dist目录
		copy: {
			html: {
				expand: true,
				src: '*.html',
				dest: 'dist'
			},
			vendor: {
				expand: true,
				src: 'vendor/**',
				dest: 'dist'
			}
		},
		// 动态监听文件的更改并执行相应的任务
		watch: {
			development: {
				files: ['less/*.less', 'js/*.js'],
				tasks: ['clean', 'less', 'autoprefixer', 'csslint', 'concat', 'jshint', 'watch'],
			},
			production: {
				files: ['less/*.less', 'js/*.js'],
				tasks: ['clean', 'htmlmin', 'less', 'autoprefixer', 'csslint', 'cssmin', 'jshint', 'uglify', 'concat'],
			}
		}
	});

	// 加载插件
	grunt.loadNpmTasks('grunt-contrib-clean');
	grunt.loadNpmTasks('grunt-contrib-htmlmin');
	grunt.loadNpmTasks('grunt-contrib-less');
	grunt.loadNpmTasks('grunt-autoprefixer');
	grunt.loadNpmTasks('grunt-contrib-csslint');
	grunt.loadNpmTasks('grunt-contrib-cssmin');
	grunt.loadNpmTasks('grunt-contrib-concat');
	grunt.loadNpmTasks('grunt-contrib-jshint');
	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.loadNpmTasks('grunt-contrib-watch');
	grunt.loadNpmTasks('grunt-contrib-copy');

	// 默认被执行的任务列表。
	grunt.registerTask('default', ['clean', 'less', 'autoprefixer', 'csslint', 'concat', 'jshint', 'watch:development']);
	grunt.registerTask('production', ['clean','less','cssmin', 'concat', 'uglify','copy','watch:production']);

};